package handler

import (
	"github.com/gin-gonic/gin"
	"lucidity.note/app/common/bean"
	"lucidity.note/app/service"
)

func RegisterRemoteSyncRouter(router *gin.Engine) {
	group := router.Group("/remote")
	{
		group.PUT("/sync/:notebookid", syncRemoteRepositoryHandler)
	}
}

func syncRemoteRepositoryHandler(ctx *gin.Context) {
	var notebookId = ctx.Param("notebookid")
	response := &bean.ResponseParam{}
	service := &service.RemoteSyncService{}
	if data, err := service.SyncRemoteRepositoryService(notebookId); nil != err {
		response.Failure(err.Error())
	} else {
		response.Data = data
		response.Succeed("远程同步成功")
	}
	ctx.JSON(response.Status, response)
}
